package com.atstudy.service;

import com.atstudy.dao.AccountDao;
import com.atstudy.entites.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;

import javax.sql.DataSource;
import java.util.List;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/1/31 9:23
 * @copyright: 博为峰
 */
@Service("accountService")
/*@Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED,
        timeout = -1, readOnly = false, rollbackFor = RuntimeException.class)*/
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Override
    public List<Account> getAccountList() {
        return accountDao.selectAccountList();
    }

    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED,
            timeout = -1, readOnly = false, rollbackFor = RuntimeException.class)
    @Override
    public int transfer(final String from, final String to, final int balance) {
        accountDao.updateAccount(from, -balance);
        System.out.println(1 / 0);
        accountDao.updateAccount(to, balance);
        return 0;
    }
}
